namespace Pinwheel.Kernel
{
    public interface IServiceManager
    {
        ServiceManagerConfig Config { get; }
        
        string NodeName { get; }
        
        List<NodeConfig> NodeList { get; }
        
        TaskFactory Factory { get; }
        
        PID StartNewService<TService>(string? alias = null) where TService : IServiceInstance, new();
        
        IService CreateService<TService>(out PID pid, string? alias = null) where TService : IServiceInstance, new();
        
        ServiceStatus RegisterService<TService>(PID pid, TService service, string? alias = null) where TService : IService;
        
        ServiceStatus UnregisterService(PID pid);
        
        ServiceStatus StartService(PID pid);
        
        ServiceStatus StartServiceInstance<TService>(TService service) where TService : IServiceInstance;
        
        ServiceStatus StartServiceAgent<TService>(TService service) where TService : IServiceAgent;
        
        bool RenameService(PID pid, string alias);
        
        bool RenameService<TService>(TService service, string alias) where TService : IServiceInstance;
        
        IService GetService(PID pid);
        
        IService GetService(string alias);

        PID GetServicePID(string alias);
        
        string GetServiceName(PID pid);
        
        string GetServiceName(IService service);
        
        bool TryGetService<TService>(PID pid, out TService service) where TService : IService;
        
        bool TryGetService<TService>(string alias, out TService service) where TService : IService;
        
        ServiceStatus StopService(PID pid);
        
        ServiceStatus StopServiceInstance<TService>(TService service) where TService : IServiceInstance;
        
        ServiceStatus StopServiceAgent<TService>(TService service) where TService : IServiceAgent;
        
        
        void Send(PID source, PID dest, string method, MessageType type, IMessage message);
        
        void Send(PID source, string alias, string method, MessageType type, IMessage message);
        
        Task<IMessage> Call(PID source, PID dest, string method, MessageType type, IMessage message, int timeout = 5000);
        
        Task<IMessage> Call(PID source, string alias, string method, MessageType type, IMessage message, int timeout = 5000);
        
    }
}
